import java.io.InputStream;
import java.net.ServerSocket;
import java.net.Socket;
import java.security.KeyFactory;
import java.security.PublicKey;
import java.security.Signature;
import java.security.spec.X509EncodedKeySpec;

public class RSA_server{
	public static void main(String[] args)throws Exception{
		ServerSocket server = new ServerSocket(8000);
		Socket soc = server.accept();
		InputStream input = soc.getInputStream();
		Thread.sleep(500);
		byte[] clipPubKey = new byte[input.available()];
		input.read(clipPubKey);
		Thread.sleep(500);
		byte[] data = new byte[input.available()];
		input.read(data);
		Thread.sleep(500);
		byte[] signdata = new byte[input.available()];
		input.read(signdata);
		KeyFactory kf = KeyFactory.getInstance("RSA");
		PublicKey pubkey = kf.generatePublic(new X509EncodedKeySpec(clipPubKey));
		Signature sign = Signature.getInstance("SHA256withRSA");
		sign.initVerify(pubkey);
		sign.update(data);
		boolean verify = sign.verify(signdata);
		System.out.println(verify);
		server.close();

	}
}
